package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextFormat;
	import fl.containers.ScrollPane;
	
	
	public class tree extends Sprite
	{
		static public const TREE_WIDTH:Number = 150;
		static public const TREE_HEIGHT:Number = 100;
		
		public var border:Sprite = new Sprite();
		public var tree_child_count:int = 0;
		public var area:ScrollPane = new ScrollPane();
		public var source:Sprite = new Sprite();
		
		public function tree()
		{
			addEventListener(Event.ADDED_TO_STAGE, on_added);
			addChild(border);
			init_border();
			addChild(area);
			area.setSize(TREE_WIDTH, TREE_HEIGHT);
			area.source = source;
			area.verticalScrollPolicy = "off";
			area.horizontalScrollPolicy = "auto";
			area.horizontalScrollBar.height = 20;
		}
		
		private function on_added(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, on_added);
		
		}
		
		private function init_border():void 
		{
			border.graphics.lineStyle(1, 0);
			border.graphics.drawRect(0, 0, TREE_WIDTH, TREE_HEIGHT);
		}
		
		public function addTreeChild(tc:treechild):void
		{
			tree_child_count++;
			source.addChild(tc);
			tc.y = treechild.TREE_CHILD_RADIUS+treechild.TREE_CHILD_MARGIN;
			tc.x = tree_child_count * (treechild.TREE_CHILD_WIDTH + treechild.TREE_CHILD_MARGIN) - treechild.TREE_CHILD_RADIUS;
			tc.title.text = tree_child_count.toString();
			tc.title.setTextFormat(new TextFormat(null, 10, tc.color == stone.COLOR_BLACK?0xffffff:0, true));
			
			tc.title.x -= tc.title.textWidth / 2;
			tc.title.y -= tc.title.textHeight / 2;
			area.update();
			area.horizontalScrollBar.setScrollPosition(area.maxHorizontalScrollPosition);
		}
	}

}


